﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BEX.WebUI.Entities;

namespace BEX.WebUI.Controllers
{
    public class FlatRuleController : Controller
    {
        private BTC_SMSEntities db = new BTC_SMSEntities();

        //
        // GET: /FlatRule/

        public ActionResult Index()
        {
            var account_rule_flat = db.ACCOUNT_RULE_FLAT.Include(a => a.ACCOUNT).Include(a => a.ALERT_RULE_FLAT);
            return View(account_rule_flat.ToList());
        }

        //
        // GET: /FlatRule/Details/5

        public ActionResult Details(int id )
        {
            ACCOUNT_RULE_FLAT account_rule_flat = db.ACCOUNT_RULE_FLAT.Find(id);
            if (account_rule_flat == null)
            {
                return HttpNotFound();
            }
            return View(account_rule_flat);
        }

        //
        // GET: /FlatRule/Create

        public ActionResult Create()
        {
            ViewBag.ACCOUNT_ID = new SelectList(db.ACCOUNTs, "ACCOUNT_ID", "EMAIL");
            ViewBag.RULE_ID = new SelectList(db.ALERT_RULE_FLAT, "ID", "ID");
            return View();
        }

        //
        // POST: /FlatRule/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(ACCOUNT_RULE_FLAT account_rule_flat)
        {
            if (ModelState.IsValid)
            {
                //account_rule_flat.ACCOUNT_ID = Guid.NewGuid();
                db.ACCOUNT_RULE_FLAT.Add(account_rule_flat);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ACCOUNT_ID = new SelectList(db.ACCOUNTs, "ACCOUNT_ID", "EMAIL", account_rule_flat.ACCOUNT_ID);
            ViewBag.RULE_ID = new SelectList(db.ALERT_RULE_FLAT, "ID", "ID", account_rule_flat.RULE_ID);
            return View(account_rule_flat);
        }

        //
        // GET: /FlatRule/Edit/5

        public ActionResult Edit(int id )
        {
            ACCOUNT_RULE_FLAT account_rule_flat = db.ACCOUNT_RULE_FLAT.Find(id);
            if (account_rule_flat == null)
            {
                return HttpNotFound();
            }
            ViewBag.ACCOUNT_ID = new SelectList(db.ACCOUNTs, "ACCOUNT_ID", "EMAIL", account_rule_flat.ACCOUNT_ID);
            ViewBag.RULE_ID = new SelectList(db.ALERT_RULE_FLAT, "ID", "ID", account_rule_flat.RULE_ID);
            return View(account_rule_flat);
        }

        //
        // POST: /FlatRule/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(ACCOUNT_RULE_FLAT account_rule_flat)
        {
            if (ModelState.IsValid)
            {
                db.Entry(account_rule_flat).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ACCOUNT_ID = new SelectList(db.ACCOUNTs, "ACCOUNT_ID", "EMAIL", account_rule_flat.ACCOUNT_ID);
            ViewBag.RULE_ID = new SelectList(db.ALERT_RULE_FLAT, "ID", "ID", account_rule_flat.RULE_ID);
            return View(account_rule_flat);
        }

        //
        // GET: /FlatRule/Delete/5

        public ActionResult Delete(int id )
        {
            ACCOUNT_RULE_FLAT account_rule_flat = db.ACCOUNT_RULE_FLAT.Find(id);
            if (account_rule_flat == null)
            {
                return HttpNotFound();
            }
            return View(account_rule_flat);
        }

        //
        // POST: /FlatRule/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ACCOUNT_RULE_FLAT account_rule_flat = db.ACCOUNT_RULE_FLAT.Find(id);
            db.ACCOUNT_RULE_FLAT.Remove(account_rule_flat);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}